#include "clientHead/order_analyse.h"

int logIn(){
   struct spwd* sp;
   char* passwd;
   char name[50] = {0};
   char salt[512] = {0};
   printf("请输入您的用户名:");
   scanf("%s", name);
   passwd = getpass("请输入您的密码:");
   sp = getspnam(name);
   ERROR_CHECK(sp, NULL, "client getspnam");
   getSalt(salt, sp->sp_pwdp);

   if(strcmp(crypt(passwd, salt), sp->sp_pwdp)==0){
       printf("已登陆!\n");
       return 0;
   }
   else{
       printf("验证失败!\n");
       return 1;
   }
}

void getSalt(char* salt, char* password){
    int i,j;
    for(i = 0,j = 0; password[i]&&j!=3; ++i){
        if(password[i] == '$')
            ++j;
    }
    strncpy(salt, password, i-1);
}
